//
//  KKStatusToolBarView.swift
//  SinaWeiBo
//
//  Created by King.Kong. on 16/5/27.
//  Copyright © 2016年 King.Kong. All rights reserved.
//

import UIKit

class KKStatusToolBarView: UIView {

    //添加视图模型属性
    var statusViewModel: KKStatusViewModel? {
        didSet {
            repostBtn.setTitle(statusViewModel?.repostsText, forState: .Normal)
            commentBtn.setTitle(statusViewModel?.commentsText, forState: .Normal)
            ohYeahBtn.setTitle(statusViewModel?.attitudesText, forState: .Normal)
        }
    }

    override init(frame: CGRect) {
        
        super.init(frame: frame)
        setupUI()
        backgroundColor = UIColor(white: 0.95, alpha: 1)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //设置界面
    private func setupUI() {
        addChildBtn(repostBtn, title: "转发", imageName: "timeline_icon_retweet")
        addChildBtn(commentBtn, title: "评论", imageName: "timeline_icon_comment")
        addChildBtn(ohYeahBtn, title: "赞", imageName: "timeline_icon_like")
        
        //子视图等宽平分父视图
        repostBtn.snp_makeConstraints { (make) in
            make.left.top.bottom.equalTo(self)
        }
        commentBtn.snp_makeConstraints { (make) in
            make.left.equalTo(repostBtn.snp_right)
            make.top.bottom.equalTo(repostBtn)
            make.width.equalTo(repostBtn.snp_width)
        }
        
        ohYeahBtn.snp_makeConstraints { (make) in
            make.left.equalTo(commentBtn.snp_right)
            make.top.bottom.equalTo(commentBtn)
            make.right.equalTo(self)
            make.width.equalTo(repostBtn.snp_width)
        }
        
        
        //添加分割线
        let sepView1 = lineView()
        let sepView2 = lineView()
        let width = 1 / UIScreen.mainScreen().scale
        addSubview(sepView1)
        addSubview(sepView2)
        sepView1.snp_makeConstraints { (make) in
            make.left.equalTo(commentBtn.snp_left)
            make.centerY.equalTo(self.snp_centerY)
            //黄金分割比  1 : 0.618
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.width.equalTo(width)
        }
        
        sepView2.snp_makeConstraints { (make) in
            make.left.equalTo(commentBtn.snp_right)
            make.centerY.equalTo(self.snp_centerY)
            //黄金分割比  1 : 0.618
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.width.equalTo(width)
        }
    }
    
    private func lineView() -> UIView {
        let line = UIView()
        //设置颜色
        line.backgroundColor = UIColor.purpleColor()
        
        return line
    }
    
    
    private func addChildBtn(btn: UIButton, title: String, imageName: String) {
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.setTitle(title, forState: .Normal)
        //设置文字大小
        btn.titleLabel?.font = UIFont.systemFontOfSize(10)
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        //添加到父视图上
        //自适应大小
        btn.sizeToFit()
        self.addSubview(btn)
    }
    //懒加载控件
    private lazy var repostBtn: UIButton = UIButton()
    private lazy var commentBtn: UIButton = UIButton()
    private lazy var ohYeahBtn: UIButton = UIButton()

}
